#ifndef __COMPONENT_RANDOM_FEED_BEHAVIOR_H__
#define __COMPONENT_RANDOM_FEED_BEHAVIOR_H__

#include "ComponentBehavior.hpp"
#include "Engine/MathUtils.hpp"
#include "Engine/Vector2.hpp"

#include "EasyMachine.hpp"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{

    struct ComponentRandomFeedBehavior;
    struct ComponentCreature;
    struct ComponentPathfinding;

    class SubsystemTerrain;

    struct ComponentRandomFeedBehavior : public ComponentBehavior
    {
    protected:
        enum class MachineState
        {
            Inactive,           // 不活跃的
            Move,
            LookAround,
            Feed
        };

        class StateMachine : public EasyMachine<MachineState>
        {
        private:
            ComponentRandomFeedBehavior * m_feedBehavior;
        public:
            StateMachine(ComponentRandomFeedBehavior *feedBehavior);

            virtual void enter() override;
            virtual void update(float dt) override;
            virtual void leave() override;
        };

    protected:
        float m_importanceLevel = 1.0f;
        float m_feedTime;
        float m_waitTime;
        Vector3 m_feedPosition;
        bool m_autoFeed;
        bool m_isFeed;

        StateMachine *m_stateMachine;

    public:
        ComponentCreature *componentCreature;
        ComponentPathfinding *componentPathfinding;

        SubsystemTerrain* subsystemTerrain;

        ComponentRandomFeedBehavior() = default;
        ~ComponentRandomFeedBehavior();

        virtual float getImportanceLevel() override;
        bool getIsFeed();
        void setIsFeed(bool feed);
        void feed(const Vector3& feedPosition);


        virtual void update(float dt) override;
        virtual void load(const nlohmann::json &jsonData) override;
        virtual const std::string &getName() const override;
        static const std::string &GetName();
    };
}

#endif
